package main

import (
	"blog/configs"
	_ "blog/docs"
	"blog/handlers"
	"github.com/gofiber/fiber/v2"
	"github.com/gofiber/fiber/v2/middleware/compress"
	"github.com/gofiber/fiber/v2/middleware/cors"
	"github.com/gofiber/fiber/v2/middleware/logger"
	"github.com/gofiber/fiber/v2/middleware/recover"
	swagger "github.com/swaggo/fiber-swagger"
	"log"
)

// @title kkkunny个人博客API接口文档
// @version 1.0
// @description 无
// @termsOfService https://kkkunny.top/
// @contact.name API kkkunny
// @contact.email 1401289859@qq.com
// @host 127.0.0.1:8080
// @BasePath /
// @schemes http
func main() {
	app := fiber.New()

	app.Use(recover.New())
	app.Use(logger.New())
	if configs.DEBUG {
		app.Use(cors.New())
	}
	app.Use(compress.New())

	if configs.DEBUG {
		app.Get("/swagger/*", swagger.WrapHandler)
	}
	app.Static("/", configs.FrontPath)

	api := app.Group("/api")
	{
		api.Get("/tip", handlers.GetTip)
		api.Get("/admin", handlers.GetAdminInfo)
		api.Get("/captcha", handlers.GetCaptcha)
		api.Get("/login", handlers.Login)
		api.Get("/small_articles", handlers.GetSmallArticlesByPage)
		api.Get("/article", handlers.GetArticle)
		api.Get("/column", handlers.GetColumns)
		api.Get("/tag", handlers.GetTags)
	}
	admin := api.Group("/admin", handlers.AdminTokenCheck)
	{
		admin.Get("/test", handlers.AdminTest)
		admin.Post("/image", handlers.UploadImage)
		admin.Post("/info", handlers.UpdateAdminInfo)
		admin.Post("/column", handlers.UpdateColumn)
		admin.Delete("/column", handlers.DeleteColumn)
		admin.Delete("/columns", handlers.DeleteColumns)
		admin.Post("/tag", handlers.UpdateTag)
		admin.Delete("/tag", handlers.DeleteTag)
		admin.Delete("/tags", handlers.DeleteTags)
		admin.Post("/article", handlers.UpdateArticle)
		admin.Delete("/article", handlers.DeleteArticle)
		admin.Delete("/articles", handlers.DeleteArticles)
	}

	if configs.DEBUG {
		log.Fatalln(app.Listen(":8080"))
	} else {
		log.Fatalln(app.ListenTLS(":8080", configs.CrtPath, configs.KeyPath))
	}
}
